# Create your views here.
import urllib, urllib2
import os, stat, time, sha, sys
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response
import django.utils.simplejson as jsondata
from activitystream.lib.xml2dict import fromstring

from conf.BookmarkConf import BookmarkConf
from BookmarkData import BookmarkData

def render(template, payload):        
    return render_to_response(template, payload)

def index(request):
    bData = BookmarkData()
    tags = bData.getUserTags()
    userBookMarks = bData.getBookMarks()
    payload = dict(bookMarkTags = tags, bookMarks = userBookMarks)
    return render('bookmarks.html', payload)

def bookmarksByTag(request,tag_name):
    bData = BookmarkData()
    tags = bData.getUserTags()
    #url = 'http://feeds.delicious.com/v2/json/'+getUserName()+'/'+tag_name+'?count=10'
    json = bData.getBookMarksByTag(tag_name)#processUrl(url)
    if not json:
        import sys
        print >> sys.stderr, 'No response. Perhaps slideshare down?'
        sys.exit(1)        
    payload = dict(bookMarkTags = tags, bookMarks = json,tagname = tag_name)
    return render('bookmark-bytags.html', payload)

def bookMarkStratup(request):
    payload = dict(tagname = 'startup')
    return render('bookmark-startup.html', payload)

def bookMarkEvent(request):
    payload = dict(tagname = 'event')
    return render('bookmark-event.html', payload)

def bookMarkPhp(request):
    payload = dict(tagname = 'php')
    return render('bookmark-php.html', payload)

def bookMarkArchitecture(request):
    payload = dict(tagname = 'architecture')
    return render('bookmark-architecture.html', payload)

def bookMarkJava(request):
    payload = dict(tagname = 'java')
    return render('bookmark-java.html', payload)